package com.orange.notificationsummary.event.pil.defaultimpl;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.provider.ContactsContract;
import android.provider.ContactsContract.RawContacts;
import android.widget.LinearLayout;

import com.orange.homescreen.pil.NotificationSummaryInterface;
import com.orange.homescreen.pil.PILInterfaceManager;
import com.orange.notificationsummary.R;
import com.orange.notificationsummary.utils.Constants.EventType;
import com.orange.notificationsummary.utils.LogHelper;
import com.orange.notificationsummary.utils.NtfcUtils;

public class SmsEvent extends BaseEvent implements EventType {
	private static final String	TAG	= "SmsEvent";

	public SmsEvent(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void lookDetail() {
		// TODO Auto-generated method stub
		Intent intent = new Intent(Intent.ACTION_VIEW,
				Uri.parse("content://mms-sms/conversations/" + threadId));
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		// context.startActivity(intent);
		NtfcUtils.startActivity(context, intent);
	}

	@Override
	protected void setContactPicture() {
		// TODO Auto-generated method stub
		mLayoutWidth = (int) mResources
				.getDimension(R.dimen.summary_contact_thumbnail_width);
		mLayoutHeight = (int) mResources
				.getDimension(R.dimen.summary_contact_thumbnail_height);
		mLayout.setLayoutParams(new LinearLayout.LayoutParams(mLayoutWidth,
				mLayoutHeight));
		if (contacts_image != null) {
			mContact_image.setImageBitmap(contacts_image);
		} else {
			mContact_image
					.setImageResource(R.drawable.notifications_v2_photo_placeholder);
		}
	}

	@Override
	public void showCallDialog() {
		// TODO Auto-generated method stub
		try {
			NotificationSummaryInterface mNotificationSummaryInterface = (NotificationSummaryInterface) PILInterfaceManager
					.getInterface(NotificationSummaryInterface.class);

			mNotificationSummaryInterface.updateCallLogStatusByIds(context,
					mNotificationSummaryInterface.getIdsByNumber(evnet_number,
							context));
		} catch (Exception e) {
			LogHelper.e(TAG, "showCallDialog. ", e);
		}
		Uri uri = Uri.parse("tel:" + evnet_number);
		Intent intent = new Intent(Intent.ACTION_CALL, uri);
		// context.startActivity(intent);
		NtfcUtils.startActivity(context, intent);
	}

	@Override
	public void showContactDialog() {
		// TODO Auto-generated method stub
		Bundle map = new Bundle();
		map.putCharSequence(ContactsContract.Intents.Insert.PHONE, evnet_number);

		int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
		// if (sdkVersion < Build.VERSION_CODES.ECLAIR) {
		// context.startActivity(new Intent(Intent.ACTION_INSERT_OR_EDIT)
		// .setType(People.CONTENT_ITEM_TYPE).putExtras(map));
		// } else {
		// context.startActivity(new Intent(Intent.ACTION_INSERT_OR_EDIT)
		// .setType(RawContacts.CONTENT_ITEM_TYPE).putExtras(map));
		// }

		String type = "";
		if (sdkVersion < Build.VERSION_CODES.ECLAIR) {
			type = People.CONTENT_ITEM_TYPE;
		} else {
			type = RawContacts.CONTENT_ITEM_TYPE;
		}
		Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
		intent.setType(type);
		intent.putExtras(map);
		NtfcUtils.startActivity(context, intent);
	}

	@Override
	public void showMsgDialog() {
		// TODO Auto-generated method stub
		Uri messageUri = Uri.parse("smsto:" + evnet_number);
		Intent it = new Intent(Intent.ACTION_SENDTO, messageUri);
		// context.startActivity(it);
		NtfcUtils.startActivity(context, it);
	}

}
